﻿using System.ComponentModel.DataAnnotations;

namespace Falafel.Services.Web.Models
{
    public static class OrderRules {

		/// <summary>
		/// Single Field Custom Validation: Order Total must be at least $100
		/// </summary>
        public static ValidationResult MinimumOrderAmount(decimal total, ValidationContext context) {
            if (total >= 100)
            {
            	return ValidationResult.Success;
            }
			return new ValidationResult("There is a minimum order amount of $100.", new[] { "Total" });
        }

		/// <summary>
		/// Class Level Validation: If State = CA, Total cannot exceed 1000
		/// </summary>
        public static ValidationResult CaliforniaOrderLimit(Order order, ValidationContext context) {
            if (order.State == null)
            {
            	return ValidationResult.Success;
            }

			if (order.State.Code == "CA" && order.Total > 1000)
			{
                return new ValidationResult("Orders cannot exceed $1000 for the state of California.", new[] { "Total" });
            }
            return ValidationResult.Success;
        }
    }
}
